package com.example.schoolblog.blog.Controller;

import com.example.schoolblog.blog.Dto.PaginationDTO;
import com.example.schoolblog.blog.Service.QuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;


@Controller
public class IndexController {

    @Autowired
    private QuestionService questionService;

    @GetMapping("/")
    /*
    访问主页跳转进此控制器
    */
    public String hello(Model model,
                        @RequestParam(name="page",defaultValue = "1")Integer page,
                        @RequestParam(name="size",defaultValue = "2")Integer size,
                        @RequestParam(name = "search",required = false) String search){
        //分页获取文章列表
        PaginationDTO pagination = questionService.list(search,page,size);
        //添加到model中方便渲染页面
        model.addAttribute("pagination",pagination);
        model.addAttribute("search",search);
        //返回index主页
        return "index";
    }
}
